6 红<template>
  <div class="app-container customer-div">
    <el-menu :default-active="listQuery.tab" class="el-menu-demo" mode="horizontal" @select="handleSelect">
      <el-menu-item index="department">本部门</el-menu-item>
      <el-menu-item index="all" v-if="priceOffCancelListForAll">全部</el-menu-item>
    </el-menu>
    <div style="margin-top: 20px">
      <!--搜索-->
      <el-form :inline="true" :model="listQuery" size="mini" label-width="130px">
        <el-form-item label="订单编号：">
          <el-input clearable v-model="listQuery.orderSn"></el-input>
        </el-form-item>
        <el-form-item label="客户名称：">
          <el-select
            clearable
            v-model="listQuery.customerId"
            filterable
            remote
            reserve-keyword
            placeholder="请输入关键词"
            :remote-method="querySearch">
            <el-option
              v-for="item in querySearchList"
              :key="item.customerId"
              :label="item.customerName"
              :value="item.customerId">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="业务员：">
          <el-cascader
            clearable
            size="mini"
            collapse-tags
            :show-all-levels="false"
            v-model="listQuery.userId"
            placeholder="请选择部门/事业部/人员"
            :options="userList"
            :props="props"></el-cascader>
        </el-form-item>


        <el-form-item label="申请时间：">
          <el-date-picker
            v-model="listQuery.createTime"
            type="daterange"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="回访时间：">
          <el-date-picker
            v-model="listQuery.contactTime"
            type="daterange"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审批结果：">
             <el-select v-model="listQuery.checkState" placeholder="请选择" clearable>
                <el-option label="通过"  value="0"> </el-option>
                <el-option label="不通过"  value="10"> </el-option>
             </el-select>

        </el-form-item>

        <el-form-item>
          <el-button
            @click="handleSearchList()"
            type="primary">
            查询
          </el-button>

        </el-form-item>
      </el-form>
    </div>
    <!--数据列表-->
    <div class="table-container">
      <el-table
        v-loading="loading"
        :data="list"
        border
        style="width: 100%; margin-top: 20px">
        <el-table-column
          min-width="150"
          label="订单编号"
          align="center">
          <template slot-scope="scope">
            <div>{{scope.row.orderSn}}</div>
          </template>
        </el-table-column>
        <el-table-column
          min-width="200"
          label="客户名称"
          align="center">
          <template slot-scope="scope">
            <div>{{scope.row.customerName}}</div>
          </template>
        </el-table-column>
        <el-table-column
          min-width="100"
          prop="userName"
          label="销售员"
          align="center">
        </el-table-column>
        <el-table-column
          min-width="150"
          prop="createTime"
          align="center"
          label="申请时间">
        </el-table-column>
        <el-table-column
          min-width="150"
          prop="contactTime"
          align="center"
          label="回访时间">
        </el-table-column>
        <el-table-column
          min-width="350"
          prop="customerNature"
          align="center"
          label="回访录音">
          <template slot-scope="scope">
            <div v-if="scope.row.contactFileUrl != ''">
              <audio controls style="width: 220px; height: 30px">
                <source :src="scope.row.contactFileUrl" type="audio/mpeg" />
                <source :src="scope.row.contactFileUrl" type="audio/ogg" />
                <source :src="scope.row.contactFileUrl" type="audio/mp3" />
                您的浏览器不支持该音频格式。
              </audio>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          min-width="100"
          prop="checkUserName"
          align="center"
          label="回访人">
        </el-table-column>
        <el-table-column
          min-width="100"
          prop="checkState"
          align="center"
          label="审批结果">
          <template slot-scope="scope">
             {{scope.row.checkState | fifstate}}
          </template>
        </el-table-column>
        <el-table-column
          min-width="150"
          prop="checkRemark"
          align="center"
          label="备注">
        </el-table-column>
      </el-table>
    </div>

    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[10,15,20]"
        :total="count">
      </el-pagination>
    </div>

  </div>
</template>

<script>
import { getCustomerOption,cancelApplyList} from '@/api/partner'
import {saleUserList} from '@/api/data.js'
import {formatDate} from '@/utils/date';
import store from '@/store'
import { mapGetters } from 'vuex'
const defaultListQuery={
  "tab" : "department", //all-所有，department:部门
  "orderSn" : "", //订单号
  "customerId" : '', //客户ID
  "userId" : '', //销售员
"createTime" : [], //申请时间
  "contactTime" : [], //回访时间
  "checkState" : '', //审批结果(0通过，10不通过)
  "checkUserId" : '', //回访人
  "pageNum" : 1,
  "pageSize" : 10
};
export default {
  name: "manageFmsList",
  data(){
    return{
      roles:store.getters.roles ? store.getters.roles : [],
      listQuery:JSON.parse(JSON.stringify(defaultListQuery)),
      list:[],
      count:0,
      loading:false,
      userList:[],
      querySearchList:[],
      props:{label:'value',value:'label',emitPath:false},




    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),
    priceOffCancelListForAll(){
      if(this.roles.indexOf("priceOffCancelListForAll") != -1){
        return true
      }else{
        return false
      }
    },

  },
  created() {
    this.getListData();
    this.getUserList();



  },
  filters: {
    fifstate(val) {
      if(val == 10){
        return '不通过'
      }else if(val === 0 ){
        return '通过'
      }
    },
  },
  methods:{
    handleSelect(key) {
      this.listQuery = JSON.parse(JSON.stringify(defaultListQuery))
      this.listQuery.tab = key;
      this.handleSearchList();
    },
    getUserList(){
      saleUserList().then((res)=>{
        this.userList = res
      })
    },


    //客户名称输入匹配
    querySearch(queryString){
      let data = {};
      data.keywords = queryString;
      getCustomerOption(data).then((res)=>{
        this.querySearchList = res;
      })
    },


    handleSearchList(){
      this.listQuery.pageNum = 1;
      this.getListData();
    },

    handleSizeChange(val){
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getListData();
    },
    handleCurrentChange(val){
      this.listQuery.pageNum = val;
      this.getListData();
    },

    getListData(){
      this.loading = true;
      cancelApplyList(this.listQuery).then((res)=>{
        this.list = res.list;
        this.count = res.count;
        this.loading = false;
      }).catch(()=>{
        this.loading = false;
      })
    },

  },
}
</script>


